package redpacket.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {

    public static final String EXCHANGE = "rp.exchange";
    public static final String GRAB_QUEUE = "rp.grab.queue";
    public static final String GRAB_ROUTING_KEY = "grab";

    @Bean
    public TopicExchange redPacketExchange() {
        return new TopicExchange(EXCHANGE, true, false);
    }

    @Bean
    public Queue grabQueue() {
        return QueueBuilder.durable(GRAB_QUEUE).build();
    }

    @Bean
    public Binding grabBinding(Queue grabQueue, TopicExchange redPacketExchange) {
        return BindingBuilder.bind(grabQueue).to(redPacketExchange).with(GRAB_ROUTING_KEY);
    }
}
